<template>
	<view class="main">
		<view class="carousel-section">
			<!-- 标题栏和状态栏占位符 -->
		</view>
		<!-- <uni-notice-bar show-close="true" show-icon="true" scrollable="true" single="true" text="单行的ddddddddddddddd通告栏">
		</uni-notice-bar> -->
		<!--分类-->
		<!-- <view class="fenlei">
			<view class="padding-sm" v-for="(item,index) in ColorList" :key="index" v-if="index<12">
				<view class="">
					<view class="text-lg">
						<image :src="item.image" mode="widthFix">></image>
					</view>
					<view class="margin-top-sm text-Abc">{{item.name}}</view>
				</view>
			</view>
		</view> -->
		<view class="page__bd">
			<view class="weui-grids1">
				<view>
					<view class="weui-grid1" hover-class="weui-grid_active" v-for="(item,index) in fllist" :key="index" @tap="goCustomers(index)"
					 v-if="item.isShow">
						<image class="weui-grid__icon" :src="item.image" mode="widthFix" />
						<view class="weui-grid__label ">{{item.name}}</view>
					</view>
				</view>
			</view>
		</view>
		<tabBar></tabBar>
	</view>
</template>

<script>
	import tabBar from "../../components/tabBar.vue"
	import uniNoticeBar from "../../components/uni-notice-bar/uni-notice-bar.vue"
	import * as sypower from '@/syApis/sypower/sypower.js';
	import * as Api from '@/syApis/sySet/sySet.js';
	// import * as Api1 from '@/syApis/sySet/sySet.js';
	import * as GetApi from '@/syApis/syHttp/Http.js';
	export default {
		components: {
			tabBar,
			uniNoticeBar
		},
		data() {
			return {
				fllist: [{
						image: "/static/home/OrderManger.png",
						name: "单据管理",
						url: '/pages/orderOptions/orderOptions',
						isShow: true
					},
					{
						image: "/static/home/userOrder.png",
						name: "引用验单",
						url: '/pages/gridOrder/grid',
						isShow: true
					},
					{
						image: "/static/home/bbQuite.png",
						name: "报表查询",
						url: "/pages/orderList/orderList?type=1",
						isShow: true
					},
					{
						image: "/static/home/daManger.png",
						name: "档案查询",
						url: "/pages/orderList/orderList?type=0",
						isShow: true
					},
					{
						image: "/static/home/OrderLook.png",
						name: "单据查看",
						url: "../grid/grid?type=0",
						isShow: true
					},
					{
						image: "/static/home/pdManger.png",
						name: "盘点",
						url: "../more/more",
						isShow: true
					},
					{
						image: "/static/xiSetting.png",
						name: "系统设置",
						url: "../my/my",
						isShow: true
					}
				]
			}
		},
		onLoad(options) {
			console.log("onLoad");
			this.getBarcodeRule();
			console.log("111");
			this.getGain_AllUsersRoot();
			this.getSystemSettingInfo();
			this.getDefaultSettingInfo();

		},
		onShow() {
			
		},
		methods: {
			//获取默认设置信息
		   getDefaultSettingInfo() {
				let data = {};
				var that = this;
				Api.Get_Set_Default(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "No connection could be made because the target machine actively refused it") {
			
						} else if (res.data.ErrorMsg != "") {
			
						} else {
							//赋值数组
							let settingList = res.data.ResultMsg;
							uni.setStorageSync("settingList", JSON.stringify(settingList)); //存储默认设置
							// that.settingList 
						}
					} else {
			
					}
				})
			},
			getSystemSettingInfo() {
				let data = {};
				var that = this;
				Api.Select_SystemSetup(data, function(res) {
					if (res.state) {
						if (res.data.ErrorMsg == "No connection could be made because the target machine actively refused it") {

						} 
						else if(res.data.ErrorMsg == '获取登录信息失败'){
							
						}
						else if (res.data.ErrorMsg != "") {

						} else {
							// //console.tablele(res.data.ResultMsg);
							//赋值数组
							let SystemSettingInfo = res.data.ResultMsg;
							uni.setStorageSync("SystemSettingInfo", JSON.stringify(SystemSettingInfo)); //存储系统设置

						}
					} else {

					}
				})
			},
			onNavigationBarButtonTaps(e) {
				const index = e.index;
				console.log(index);
				if (index === 0) {
					this.tel();
				} else if (index === 1) {}
			},
			//获取登录权限设置的内容
			getGain_AllUsersRoot() {
				uni.showLoading({
					title: "加载中...",
					mask:false
				})
				var UserID = uni.getStorageSync("UserCode");
				let data = {
					UserID: UserID
				};
				var that = this;
				sypower.Gain_AllUsersRoot(data, function(res) {
					uni.hideLoading();
					// sypower.showTip("加载成功");
					if (res.state) {
						if (res.data.ErrorMsg == "No connection could be made because the target machine actively refused it") {

						} else if (res.data.ErrorMsg != "") {

						} else {
							let PDA_Price_Module = [],
								PDA_Price_Module2 = [],
								PDA_Store_Module = [],
								PDA_Module_Android = [],
								PDA_Module_Options = [];
							PDA_Price_Module = res.data.ResultMsg.PDA_Price_Module;
							PDA_Price_Module2 = res.data.ResultMsg.PDA_Price_Module2;
							PDA_Store_Module = res.data.ResultMsg.PDA_Store_Module;
							res.data.ResultMsg.PDA_Module_Android.forEach((item, index) => {
								if (item.ModuleName == '引用验单') {
									if (item.IsBill == "") {
										that.fllist[1].isShow = false;
									}
								}
								if (item.ModuleName == '单据管理') {
									if (item.IsBill == "") {
										that.fllist[0].isShow = false;
									}
								}

								if (item.UType == 1) {
									PDA_Module_Android.push(item);
								} else {
									PDA_Module_Options.push(item);
								}
							});
							uni.setStorageSync("PDA_Price_Module", JSON.stringify(PDA_Price_Module)); //存储单价权限
							uni.setStorageSync("PDA_Price_Module2", JSON.stringify(PDA_Price_Module2)); //存储商品信息显示权限
							uni.setStorageSync("PDA_Store_Module", JSON.stringify(PDA_Store_Module)); //存储仓库权限
							uni.setStorageSync("PDA_Module_Android", JSON.stringify(PDA_Module_Android)); //存储单据权限
							uni.setStorageSync("PDA_Module_Options", JSON.stringify(PDA_Module_Options)); //存储功能权限
						}
					} else {
						sypower.showTip("服务器超时")
					}
				})
			},
			//初始化条码规则
			getBarcodeRule() {
				
				var that = this;
				GetApi.Select_BarcodeRule('', function(res) {
					if (res.state) {
						if(res.data.ErrorMsg !=""){
							console.log(res.data.ErrorMsg)
						}else{
							// res.data.ResultMsg[0]
							uni.setStorageSync("BarCode",JSON.stringify(res.data.ResultMsg[0]))
						}
						// console.log('获取条码规则成功')
						// console.log(res.data.ResultMsg[0])
						
					} else {
						GetApi.showTip("服务器超时")
					}
				})
			},

			//扫码获取商品
			tel: function() {
				this.current = -1;
				// 调起条码扫描
				var _this = this;
				uni.scanCode({
					scanType: 'barCode',
					success: function(res) {
						_this.GetBarcodeGoodsMessageModel(res.result);
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					},
					fail(e) {
						console.log(e);
					}
				});
			},
			//跳转到客户
			goCustomers: function(e) {
				var $this = this;
				uni.navigateTo({
					url: $this.fllist[e].url
				})

			},
			goPage: function(e) {

			},
			toStart: function() {
				this.$refs.barcode.start({
					conserve: true,
					filename: '_doc/barcode/'
				});
			},
		}
		
	}
</script>
<style>
	@import url("../index/index.css");
	@import url("../../style/weui.css");
</style>
